<script>
  // a class representing a dependency
  // exposing it on window is necessary for testing
  window.Dep = class Dep {
    // Implement this!
    constructor() {
      this.subscribers = new Set();
    }

    depend () {
      if (activeUpdate) {
        // register the current active update
        // as a subscriber
        this.subscribers.add(activeUpdate);
      }
    }

    notify() {
      // run all subscriber
      this.subscribers.forEach(fn => {
        fn();
      });
    }

  }

  let activeUpdate;

  function autorun(update) {
    // Implement this!
    function wrappedUpdate() {
      activeUpdate = wrappedUpdate;
      // update must contain dep.depend() here, to append the new subscriber
      update()
      activeUpdate = null;
    }
    wrappedUpdate();
  }

  const dep = new Dep();

  autorun(() => {
    dep.depend();
    console.log('updated');
  });
  // should log: "updated"

  dep.notify();
  // should log: "updated"

</script>